package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.model.article.pojos.ApArticleContent;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author mgw
 * @create 2021/9/26 17:19
 */
@RestController
@RequestMapping("/api/v1/article")
public class ApArticleConller {
    @Autowired
    private ApArticleService apArticleService;

    @GetMapping("/list/{tag}/{page}/{size}")
    public ResponseResult list(
            @PathVariable(value = "tag") Integer tag,
            @PathVariable(value = "page") Integer page,
            @PathVariable(value = "size") Integer size) {
        return apArticleService.homeList(tag, page, size);

    }

    @GetMapping("/article/{id}")
    public ResponseResult<ApArticleContent> getArticle(@PathVariable(value = "id") String articleId) {
        return apArticleService.findArticleById(articleId);
    }

    @PostMapping("/article/{id}")
   public ResponseResult updateStaticUrl(@RequestParam(value = "url") String url, @PathVariable(value = "id") String articleId) {
       return apArticleService.updateStaticUrl(url,articleId);
    }
}
